import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther yangdong
 * @create 2020-05-16
 */
public class StudentDAO implements DAO<Student>{
    private static Map<Integer,Student> map=new HashMap<>();
    @Override
    public int add(Student student) {
        map.put(student.age,student);
        return 0;
    }

    @Override
    public int delete(int id) {
        map.remove(id);
        return 0;
    }

    @Override
    public int update(Student student) {
        if(map.containsKey(student.age)){
            map.put(student.age,student);
            return 0;
        }else{
            return -1;
        }

    }

    @Override
    public <E> List<E> show() {
        List<Map<Integer,Student>> list=new ArrayList<>();
        list.add(map);
        return (List<E>) list;
    }

}
